CASA0013 GIS Assessment

Part 1

In this part, two maps were produced with QGIS and RStudio seperately. They are displayed here with brief descriptions about the procedures of making the maps, as well as a critical comparison of the tools used to produce them.

  • Map created with QGIS

This a map showing the the percentage of people not born in London of each Borough with deeper blue indicating higher percentage.

Thematic map made with QGIS

Thematic map made with QGIS

The data was fetched from UK Data Services, with seperate london boundary shapefile and csv file of census data on population structure. To start making the map, add these two layers to QGIS through “Vector” tab and “Delimited Text” tab seperately in “Data Source Manager” accessed from the “Layer” menu. add layers

Before joining two layers, check the attribute table of shapefile and the csv file to make sure there is a common field that can be set as the “join field”. Then the csv data was joined to the boundary shapefile by going to the “join” tab in the “properties” window of the boundary layer. join layers

Next, display the data as desired through adjusting features under “Symbology” and “Label” tabs in the “properties” window of the boundary layer. adjust symbologies

adjust labels

adjust labels

Base map was added through “XYZ Tiles”. To load the base map options, run the python script get from the tutorial online in the “Python Console” accessed from “Plugins” menu. add basemap

Lastly, the layout was generated using “Layout Manager”. generate layout

As shown in the “Data Source Manager”, QGIS is capable of compiling various types of data and adding them via different pathes. This makes it convenient to work together with all kinds of open sourse databases. Besides, various plugins including python console are supported, which gives it possibility to be conneted with resources and functions of other platforms.

While using QGIS to display the data, the result of visualization can be reflected immediately and adjusted accordingly to best convey the information. The color, style of lines, and style of text are directly demonstrated before being chosen to be applied to the map. Besides, it is intuitive to generate layout in a GUI-based tool because there is nested functions of adding different cartographical elements and they can be easily adjusted and moved around for the desired consequence.

  • Map created with RStudio

Below are codes demonstrating the steps of building up an interactive map of the same theme and similar rendering style using the same data files and made with the Leaflet package in RStudio.

  1. Load packages
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.2.1 --
## v ggplot2 3.0.0     v purrr   0.2.5
## v tibble  1.4.2     v dplyr   0.7.6
## v tidyr   0.8.1     v stringr 1.3.1
## v readr   1.1.1     v forcats 0.3.0
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(sp)
library(rgdal)
## rgdal: version: 1.3-6, (SVN revision 773)
##  Geospatial Data Abstraction Library extensions to R successfully loaded
##  Loaded GDAL runtime: GDAL 2.2.3, released 2017/11/20
##  Path to GDAL shared files: C:/Users/alexy/Documents/R/win-library/3.5/rgdal/gdal
##  GDAL binary built with GEOS: TRUE 
##  Loaded PROJ.4 runtime: Rel. 4.9.3, 15 August 2016, [PJ_VERSION: 493]
##  Path to PROJ.4 shared files: C:/Users/alexy/Documents/R/win-library/3.5/rgdal/proj
##  Linking to sp version: 1.3-1
library(leaflet)
library(htmltools)
library(RColorBrewer)
  1. Read the London Borough boundary shapefile and census csv file from a local directory.
BoroughBd <- readOGR("C:/Users/alexy/Desktop/GIS/wk1/BoundaryDataEdinaCensus/england_lad_2011.shp")
## OGR data source with driver: ESRI Shapefile 
## Source: "C:\Users\alexy\Desktop\GIS\wk1\BoundaryDataEdinaCensus\england_lad_2011.shp", layer: "england_lad_2011"
## with 33 features
## It has 4 fields
LondonData <- read.csv("C:/Users/alexy/Desktop/GIS/wk1/LondonData.csv")
LondonData <- read_csv("C:/Users/alexy/Desktop/GIS/wk1/LondonData.csv", na = "n/a")
## Parsed with column specification:
## cols(
##   .default = col_double(),
##   Ward_name = col_character(),
##   Old_code = col_character(),
##   code = col_character(),
##   Population_2015 = col_integer(),
##   Children_aged_0_15_2015 = col_integer(),
##   Working_age_16_64_2015 = col_integer(),
##   Older_people_aged_65plus_2015 = col_integer(),
##   Median_Age_2013 = col_integer(),
##   Number_Killed_or_Seriously_Injured_on_the_roads_2014 = col_integer(),
##   In_employment_16_64_2011 = col_integer(),
##   Number_of_jobs_in_area_2013 = col_integer(),
##   Number_of_properties_sold_2014 = col_integer(),
##   Number_of_Household_spaces_2011 = col_integer()
## )
## See spec(...) for full column specifications.
  1. Manipulate the data to get a sp feature neccessary for plotting.
LondonData <- data.frame(LondonData)
LondonBoroughs <- LondonData[grep("^E09",LondonData[,3]),] # select rows of London Boroughs
LondonBoroughs <- LondonBoroughs[,c(3,16)] # select needed columns
LondonBoroughs <- LondonBoroughs[2:34,] # get rid of duplicated column
BoroughBd@data <- data.frame(BoroughBd@data,LondonBoroughs[match(BoroughBd@data[,"code"],LondonBoroughs[,"code"]),]) # join the attribute data to the SP data
names(BoroughBd)[3] <- c("Borough Name") # rename the column
## Warning in checkNames(value): attempt to set invalid names: this may lead
## to problems later on. See ?make.names
names(BoroughBd)[6] <- c("Percentage")
## Warning in checkNames(value): attempt to set invalid names: this may lead
## to problems later on. See ?make.names
BoroughBd <- BoroughBd[c(3,6)] # extract the two neccessary columns
Borough_repro <-spTransform(BoroughBd, CRS("+proj=longlat +datum=WGS84")) #reproject the data
  1. Plot the reprojected sp feature with Leaflet package and add basemap from third party tile provider.
map <- leaflet(Borough_repro)%>%setView(lng = 0, lat = 51.5, zoom = 9)
map%>%addProviderTiles(providers$Esri.WorldGrayCanvas)
  1. Set color scheme for the map.
bins <- c(10.3, 19.9, 31.0, 39.4, 48.2, 55.1)
pal <- colorBin(c("#f7fbff", "#c8ddf0","#73b3d8","#2879b9","#08306b"), domain = Borough_repro$Percentage, bins = bins)
  1. Fill the map with desired color scheme.
map%>%addPolygons(weight = 1,
                  opacity = 1, 
                  color = "#fff", 
                  smoothFactor = 0.3, 
                  fillOpacity = 1, 
                  fillColor = ~pal(Percentage))
# UNSOLVED ISSUE: the grey background of this layer cannot be get rid of, which covers the basemap
  1. Add interactive features with the “highlight” argument.
map%>%addPolygons(weight = 1,opacity = 1, color = "#fff", smoothFactor = 0.3, fillOpacity = 1, fillColor = ~pal(Percentage),
                  highlight = highlightOptions(
                    weight = 5,
                    color = "#fff",
                    fillOpacity = 1,
                    bringToFront = TRUE))
  1. Add labels with a style.
labels <- sprintf("<strong>%s</strong><br/>%g percent",Borough_repro$`Borough Name`,Borough_repro$Percentage) %>% lapply(htmltools::HTML)

map%>%addPolygons(weight = 1,opacity = 1, color = "#fff", smoothFactor = 0.3, fillOpacity = 1,fillColor = ~pal(Percentage),highlight = highlightOptions(weight = 5,color = "#fff",fillOpacity = 1,bringToFront = TRUE),
                  label = labels,
                  labelOptions = labelOptions(
                    style = list("font-weight" = "normal", padding = "3px 8px"),
                    textsize = "15px",
                    direction = "auto"))
  1. Add legend.
map%>%addLegend(pal = pal, values = ~Percentage, opacity = 0.7, title = "% people not born in UK",
                position = "bottomright")
# UNISOLVED ISSUE: the entire map becomes grey after the legend feature is added

Compared to QGIS, R is more handy for data maniputaling especially for attribute data. It is easy to clean and slice neccessary data with built-in functions in R. Besides, it is much easier to manage the project when with R when it has to be revised frequently or involves group work becaused the connection with Git makes it possible to perform version control and process the work at multiple workspaces.

As for visualization, in terms of making simple thematic map, R seems not to be inferior to a GUI-based tool since those rendering features are all subject to customization through coding. Thus, what can be generated through QGIS or ArcGIS can also be rendered with R, and R can even make the map interactive. However, the code-based nature also makes R hard to use in some ways. It takes much more efforts to get to know and become familier with the tools and functions available in R since they are not directly shown anywhere. The visualization processes also takes extra time to debugging and figuring out results that each line of code will lead to.